package pl.nazaweb.imedproplus.model.facade;

import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import pl.nazaweb.imedproplus.model.entity.Users;

@Stateless
@LocalBean
public class UserFacade extends AbstractFacade<Users> {

    @PersistenceContext(unitName = AbstractFacade.peristanceUnitName)
    private EntityManager entityManager;

    public UserFacade() {
        super(Users.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        return this.entityManager;
    }

    @Override
    public void remove(Users entity) {
        this.getEntityManager()
                .createNativeQuery("delete from users where id="+entity.getId())
                .executeUpdate();
    }

    @Override
    public void remove(List<Users> entityList) {
        for(Users user : entityList){
            this.remove(user);
        }
    }
    
    
    
    public void updatePassword(Long userId, String password){
        this.getEntityManager()
                .createNativeQuery("update users set password=:pass where id=:id")
                .setParameter("pass", password)
                .setParameter("id", userId)
                .executeUpdate();
    }
}
